package it.fuesi.synoutils.services.tasks.filestation;

import android.app.Activity;
import android.content.Context;

import it.fuesi.synoutils.activities.FileStationFileDetailActivity;
import it.fuesi.synoutils.activities.MainActivity;
import it.fuesi.synoutils.helpers.FormatHelper;
import it.fuesi.synoutils.model.base.VoidDataObject;
import it.fuesi.synoutils.model.base.VoidResponse;
import it.fuesi.synoutils.model.filestation.FileStationClientParameters;
import it.fuesi.synoutils.services.client.FileStationClient;
import it.fuesi.synoutils.services.client.ServiceClientFactory;
import it.fuesi.synoutils.services.tasks.base.BaseTask;

/**
 * Created by pascotto on 17/10/14.
 */
public class AddFolder extends BaseTask<VoidResponse, VoidDataObject, FileStationClientParameters> {

    private static final String TAG = AddFolder.class.getName();

    public AddFolder(Context context){
        super(context);
    }


    @Override
    protected String getCacheKey() {
        return null;
    }

    @Override
    public VoidResponse run(FileStationClientParameters params)  throws Exception{
            publishProgress("Adding new Folder: " + params.getName());
            FileStationClient client = ServiceClientFactory.getClient(FileStationClient.class);

            return client.addFolder(FormatHelper.urlEncode(params.getFolder_path()), FormatHelper.urlEncode(params.getName()));
    }

    @Override
    protected void onPostExecute(VoidResponse voidResponse) {
        super.onPostExecute(voidResponse);

        if(voidResponse.isSuccess()){
            MainActivity main = (MainActivity)getContext();
            main.onRefresh();
        }
    }
}
